-
Notifications
You must be signed in to change notification settings - Fork 444
[WIP] Add benchmark scripts to different moe gemms #1315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @fzyzcjy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the benchmarking capabilities for Mixture-of-Experts (MoE) General Matrix Multiplications (GEMMs) by introducing a new, more granular profiling utility. It integrates this utility into existing benchmarks to provide detailed kernel-level performance metrics, expands the range of tested configurations, and standardizes the output format for easier data processing. Additionally, it adjusts project dependencies.
Highlights
- Enhanced Benchmarking Utility: Introduced a new
bench_kineto
utility function inflashinfer/testing/utils.py
for detailed CUDA kernel profiling. This utility leverages PyTorch's Kineto profiler to measure specific kernel execution times, offering more granular performance insights than general execution time measurements. - Integration of Kineto Profiling: The
bench_cutlass_fused_moe.py
script has been updated to utilize the newbench_kineto
utility. This allows for precise measurement ofgemm1
andgemm2
kernel durations within the fused MoE operation, providing deeper analysis of performance bottlenecks. - Expanded Benchmark Configurations: The
bench_cutlass_fused_moe.py
script now includes additionalBATCH_SIZES
(384, 768) and a more dynamic generation oftest_configs
fornum_experts
, covering a wider range of expert counts (e.g., 288 // 1 down to 288 // 32). This broadens the scope of the benchmarks. - Structured Benchmark Output: The benchmark results in
bench_cutlass_fused_moe.py
are now printed as a JSON string, includingbatch_size
,num_experts
,top_k
,intermediate_size
, and the measuredtime_gemm1_us
andtime_gemm2_us
. This provides machine-readable and easily parsable output for automated analysis. - Dependency Adjustment: The
nvidia-cudnn-frontend
dependency has been commented out insetup.py
, indicating it may no longer be a required installation for the project.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with π and π on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. β©
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces benchmark scripts for MoE GEMMs and adds a new benchmarking utility. The changes are a good step towards performance analysis.
My review focuses on improving code quality, maintainability, and robustness. I've identified a potential resource leak in the new suppress_stdout_stderr
utility, which is important to fix. I've also pointed out several opportunities to clean up the code by removing unused imports, temporary comments, and commented-out code blocks, which will improve the overall maintainability of the new benchmark scripts.
class suppress_stdout_stderr: | ||
def __enter__(self): | ||
self.outnull_file = open(os.devnull, 'w') | ||
self.errnull_file = open(os.devnull, 'w') | ||
|
||
self.old_stdout_fileno_undup = sys.stdout.fileno() | ||
self.old_stderr_fileno_undup = sys.stderr.fileno() | ||
|
||
self.old_stdout_fileno = os.dup(sys.stdout.fileno()) | ||
self.old_stderr_fileno = os.dup(sys.stderr.fileno()) | ||
|
||
self.old_stdout = sys.stdout | ||
self.old_stderr = sys.stderr | ||
|
||
os.dup2(self.outnull_file.fileno(), self.old_stdout_fileno_undup) | ||
os.dup2(self.errnull_file.fileno(), self.old_stderr_fileno_undup) | ||
|
||
sys.stdout = self.outnull_file | ||
sys.stderr = self.errnull_file | ||
return self | ||
|
||
def __exit__(self, *_): | ||
sys.stdout = self.old_stdout | ||
sys.stderr = self.old_stderr | ||
|
||
os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup) | ||
os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup) | ||
|
||
os.close(self.old_stdout_fileno) | ||
os.close(self.old_stderr_fileno) | ||
|
||
self.outnull_file.close() | ||
self.errnull_file.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation of suppress_stdout_stderr
is not exception-safe, which can lead to resource leaks. Use a try...finally
block or contextlib.ExitStack
to ensure resources are always cleaned up correctly, even in case of errors.
class suppress_stdout_stderr: | |
def __enter__(self): | |
self.outnull_file = open(os.devnull, 'w') | |
self.errnull_file = open(os.devnull, 'w') | |
self.old_stdout_fileno_undup = sys.stdout.fileno() | |
self.old_stderr_fileno_undup = sys.stderr.fileno() | |
self.old_stdout_fileno = os.dup(sys.stdout.fileno()) | |
self.old_stderr_fileno = os.dup(sys.stderr.fileno()) | |
self.old_stdout = sys.stdout | |
self.old_stderr = sys.stderr | |
os.dup2(self.outnull_file.fileno(), self.old_stdout_fileno_undup) | |
os.dup2(self.errnull_file.fileno(), self.old_stderr_fileno_undup) | |
sys.stdout = self.outnull_file | |
sys.stderr = self.errnull_file | |
return self | |
def __exit__(self, *_): | |
sys.stdout = self.old_stdout | |
sys.stderr = self.old_stderr | |
os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup) | |
os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup) | |
os.close(self.old_stdout_fileno) | |
os.close(self.old_stderr_fileno) | |
self.outnull_file.close() | |
self.errnull_file.close() | |
def __exit__(self, *_): | |
sys.stdout = self.old_stdout | |
sys.stderr = self.old_stderr | |
os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup) | |
os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup) | |
os.close(self.old_stdout_fileno) | |
os.close(self.old_stderr_fileno) | |
self.outnull_file.close() | |
self.errnull_file.close() |
import os | ||
import sys | ||
import time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -35,7 +40,9 @@ | |||
96, | |||
128, | |||
256, | |||
384, # NOTE ADD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print(f"MAIN_OUTPUT=" + json.dumps(dict( | ||
batch_size=batch_size, | ||
num_experts=num_experts, | ||
top_k=top_k, | ||
intermediate_size=intermediate_size, | ||
time_gemm1_us=time_gemm1 * 1e6, | ||
time_gemm2_us=time_gemm2 * 1e6, | ||
))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flashinfer/testing/utils.py
Outdated
prof_lines = profiler.key_averages().table(sort_by='cuda_time_total', max_name_column_width=100).split('\n') | ||
# print(f"prof_lines=\n" + "\n".join(prof_lines)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# NOTE MODIFIED rm | ||
# "nvidia-cudnn-frontend", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π Description
π Related Issues
π Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
β Pre-commit Checks
pre-commit
by runningpip install pre-commit
(or used your preferred method).pre-commit install
.pre-commit run --all-files
and fixed any reported issues.π§ͺ Tests
unittest
, etc.).Reviewer Notes